<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>

</head>
<!--<script src="../static/js/vue.js"></script>-->
<script src="https://unpkg.com/vue@2.6.14/dist/vue.min.js"></script>
<script src="https://unpkg.com/http-vue-loader"></script>
<link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
<script src="https://unpkg.com/element-ui@2.15.8/lib/index.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<body>
<div id="login">
    <Login v-on:submit_form="submit_form"></Login>
    <div style="align-content: center">
        <el-alert
                style="width: 400px;margin: auto"
                v-if="msg"
                center
                title="用户名或密码错误"
                :closable="false"
                type="error">
        </el-alert>
    </div>
</div>
</body>
<script>
    Vue.use('axios');
    new Vue({
       el:'#login',
       data:{
           msg:false
       },
       components: {
           'login':httpVueLoader('../static/components/login.vue')
       },
       methods:{
           submit_form(data){
               const user={name:data.name,password:data.pass}
               console.log(JSON.stringify(user));
               axios({
                   method:'post',
                   url:'http://localhost:8080/login',
                   data:user,
                   headers: {
                       'Content-Type': 'application/json'
                   }
               }).then(res=>{
                   console.log(res.data);
                       console.log(res.data);
                       if(res.data!=""){
                           console.log(res.data);
                           this.msg=false;
                           window.location.replace("http://localhost:8080/productList.do");
                       }else {
                           this.msg=true;
                           console.log("用户名或密码错误");
                       }
               }).catch(error=>{
                   console.log(error);
               });
           }
       }
    });
</script>

</html>